﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using System.Data;

namespace BLL
{
   public class ClsThongTinThiNghiemBus
    {
       public ClsThongTinThiNghiemInfocs Info = new ClsThongTinThiNghiemInfocs();
        public DataTable SelectAll()
        {
            ClsDataAccess oConnection = new ClsDataAccess();
            string strSql = @"SELECT * FROM TTThiNghiemMau";

            if (oConnection.ExecuteSelect(strSql))
            {
                oConnection.ODataTable.Columns.Add("STT");
                int i = 0;
                foreach (DataRow oDRow in oConnection.ODataTable.Rows)
                {
                    oDRow["STT"] = (i + 1);
                    i++;
                }
                return oConnection.ODataTable;
            }
            else return null;
        }
        public DataTable SelectOne()
        {
            ClsDataAccess oConnection = new ClsDataAccess();
            string strSql = @"SELECT * FROM TTThiNghiemMau WHERE MaThiNghiem like '%" + Info.MaThiNghiem + "%'";   
            if (oConnection.ExecuteSelect(strSql))
            {
                oConnection.ODataTable.Columns.Add("STT");
                int i = 0;
                foreach (DataRow oDRow in oConnection.ODataTable.Rows)
                {
                    oDRow["STT"] = (i + 1);
                    i++;
                }
                return oConnection.ODataTable;
            }
            else return null;
        }
        public bool Them()
        {
            string strSql = "EXECUTE InsertTTThiNghiemMau '" + Info.MaThiNghiem + "', N'" + Info.CoQuanTN + "', '" + Info.NgayTN + "','" + Info.SoLanTN + "',N'" + Info.NguoiTN + "',N'" + Info.NguoiKiemTraTN + "'";
            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));
        }

        public bool Sua()
        {
            string strSql = "EXECUTE UpdateTTThiNghiemMau '" + Info.MaThiNghiem + "', N'" + Info.CoQuanTN + "', '" + Info.NgayTN + "','" + Info.SoLanTN + "',N'" + Info.NguoiTN + "',N'" + Info.NguoiKiemTraTN+ "'";
            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));
        }

        public bool Xoa()
        {
            string strSql = "EXECUTE DeleteTTThiNghiemMau'" + Info.MaThiNghiem + "'";
            ClsDataAccess oConnection = new ClsDataAccess();
            return (oConnection.ExecuteStoredProcedure(strSql));

        }
    }
}
